<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="file" accept="image/*" id="uploader" />
    <img id="preview" style="max-width: 100%" />

    <script>
      const uploader = document.querySelector('#uploader');
      const preview = document.querySelector('#preview');
      uploader.onchange = (e) => {
        const file = e.target.files[0];
        if (!file) return;
        const url = URL.createObjectURL(file);
        preview.src = url;
        preview.onload = () => URL.revokeObjectURL(url); // 加载完即释放
      };
    </script>
  </body>
</html>
